using System;
using System.Collections.Generic;
using System.Text;
using PH.Common;

namespace Hoshimi
{
    public class ExplorerBot_MoveToNavigationState : State
	{
		#region Singleton

		// Fields
		protected static ExplorerBot_MoveToNavigationState instance;

		// Constructor
		protected ExplorerBot_MoveToNavigationState() : base() { }

		// Methods
		public static ExplorerBot_MoveToNavigationState Instance()
		{
			// Uses "Lazy initialization"
			if( instance == null ) 
				instance = new ExplorerBot_MoveToNavigationState();

			return instance;
		}

		#endregion

		public override bool Play( Unit unit ) 
        {
			ExplorerBot bot = (ExplorerBot) unit;
			
            bot.SetName("Yumi navigue");

            // We can't give orders to the bot. We stop
			if ( bot.State != NanoBotState.WaitingOrders && bot.State != NanoBotState.Moving) 
			{
				return true;
			}

			if(bot.State == NanoBotState.Moving)
			{
				return true;
			}

			if (bot.IsAZNNeeded())
			{
				unit.myStateMachine.ChangeState( ExplorerBot_MoveToAZNState.Instance() );
                return false;
			}

            if (bot.IsNavigationPointReached())
            {
				bot.StopIfMoving();

				if (bot.HasToWait())
				{
					return true;
				}

				bot.DeclareNavigationPointReached();

                unit.myStateMachine.ChangeState( ExplorerBot_RestState.Instance() );
                return false;
            }

            bot.MoveToNavigationPoint();
			return true;
		}
	}
}
